//
//  HelpTableViewCell.m
//  Civacrm
//
//  Created by zhk on 2017/2/8.
//  Copyright © 2017年 王桂敏. All rights reserved.
//

#import "HelpTableViewCell.h"

@implementation HelpTableViewCell


- (void)initView{
    
    self.contentView.backgroundColor = ColorWithHexString(@"f5f7f7");
    
    self.whiteView = [UIView viewWithFrame:CGRectMake(0, 0, kScreenWidth, h(100)) bgColor:WhiteColor];
    
    [self.contentView addSubview:self.whiteView];
    
    
    self.questionTitleLabel = [UILabel labelWithTitle:nil frame:CGRectMake(w(47), 0, kScreenWidth - 90, h(100)) font:font(32) textColor:ColorWithHexString(@"4e778f") bgColor:ClearColor];
    
    self.questionTitleLabel.numberOfLines = 0;
    [self.whiteView addSubview:self.questionTitleLabel];
    
    
    self.moreButton = [UIButton buttonOfImageForNormalWithImage:@"icon_showall" frame:CGRectMake(kScreenWidth - 40, 0, w(67), w(67)) target:self action:@selector(handleMoreButonAction:)];
    
    self.moreButton.centerY = self.whiteView.centerY;
    [self.whiteView addSubview:self.moreButton];
    
    [self.whiteView addLineWithLineWidth:0.5 startPoint:CGPointMake(self.questionTitleLabel.x, h(100)) endPoint:CGPointMake(kScreenWidth, h(100)) lineColor:GlobalGray];
    
    
    self.questionContentLabel = [UILabel labelWithTitle:nil frame:CGRectZero font:font(28) textColor:ColorWithHexString(@"73a0ba") bgColor:ClearColor];
    
    [self.contentView addSubview:self.questionContentLabel];
    
    
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initView];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
    }
    return self;
    
}

- (void)configCellWithModel:(QuestionModel *)model{
    
//    self.questionTitleLabel.text = model.title;

    NSMutableAttributedString * tempStr = [[NSMutableAttributedString alloc] initWithData:[model.title dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
    [tempStr setAttributes:@{NSForegroundColorAttributeName:ColorWithHexString(@"4e778f")} range:NSMakeRange(0, tempStr.length)];
    self.questionTitleLabel.attributedText = tempStr;
    
    if (model.isOpen) {
        
//        self.questionContentLabel.text = model.content;

        
        NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithData:[model.content dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
        [str setAttributes:@{NSForegroundColorAttributeName:ColorWithHexString(@"4e778f")} range:NSMakeRange(0, str.length)];
        self.questionContentLabel.attributedText = str;
        
        
        self.questionContentLabel.frame = CGRectMake(self.questionTitleLabel.x, getMaxY(self.questionTitleLabel) + h(26), kScreenWidth - w(47) * 2, model.textRect.size.height);
        self.moreButton.tag = 10001;
        [UIView animateWithDuration:0.5 animations:^{
            self.moreButton.imageView.transform = CGAffineTransformMakeRotation(M_PI);
        }];
        
    } else {
        self.questionContentLabel.frame = CGRectZero;
        
        if (self.moreButton.tag == 10001) {
            [UIView animateWithDuration:0.5 animations:^{
                self.moreButton.imageView.transform = CGAffineTransformMakeRotation(M_PI * 2);
            }];
 
        }
    }
    
}

- (void)handleMoreButonAction:(UIButton *)sender{
    [self.tableView.delegate tableView:self.tableView didSelectRowAtIndexPath:[self.tableView indexPathForCell:self]];
    
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
